/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Views;

import Classes.Retroprojecteur;
import Classes.Secteur;
import DAO.DBConnect;
import DAO.RetroprojecteurDAO;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Map;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Kévin
 */
public class vueRetroprojecteur extends javax.swing.JFrame {

    private Map<Integer, Classes.Type> listeType;
    private Map<Integer, Secteur> listeSecteur;
    private Map<Long, Retroprojecteur> listeRetroprojecteur;
    private Retroprojecteur retroprojecteurGlobal;
    DefaultTableModel dtm;
    private vueGlobale mainFrame;

    /**
     * Creates new form vueRetroprojecteur
     */
    public vueRetroprojecteur(JFrame mainFrame, Map<Integer, Classes.Type> listeType, Map<Integer, Secteur> listeSecteur, Map<Long, Retroprojecteur> listeRetroprojecteur) {
        initComponents();

        retroprojecteurGlobal = new Retroprojecteur();
        this.listeType = listeType;
        this.listeSecteur = listeSecteur;
        this.listeRetroprojecteur = listeRetroprojecteur;

        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((dimension.getWidth() - this.getWidth()) / 2);
        int y = (int) ((dimension.getHeight() - this.getHeight()) / 2);
        this.setLocation(x, y);

        this.mainFrame = (vueGlobale) mainFrame;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton2 = new javax.swing.JButton();
        BtnAdd = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        ComboType = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        ComboYear = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        ComboSecteur = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        EDTypeLum = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        ED_NumCompta = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        ED_NumSerie = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        ED_Nom = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ED_descriptif = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        ED_Date = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        ED_Prix = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        ED_Garantie = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setText("Liste des rétroprojecteurs");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Code Barre", "Nom", "Descriptif", "Ampoule"
            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jButton2.setText("Supprimer");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        BtnAdd.setText("Ajouter");
        BtnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnAddActionPerformed(evt);
            }
        });

        jLabel2.setText("Type : ");

        ComboType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ComboTypeActionPerformed(evt);
            }
        });

        jLabel4.setText("Année : ");

        ComboYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010", "2011", "2012", "2013", "2014" }));

        jLabel5.setText("Secteur : ");

        jLabel6.setText("Type ampoule : ");

        EDTypeLum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EDTypeLumActionPerformed(evt);
            }
        });

        jLabel7.setText("Numéro Compta : ");

        jLabel8.setText("Numéro Série : ");

        jLabel9.setText("Nom : ");

        jLabel10.setText("Descriptif : ");

        ED_descriptif.setColumns(20);
        ED_descriptif.setRows(5);
        jScrollPane2.setViewportView(ED_descriptif);

        jLabel11.setText("Date achat : ");

        jLabel12.setText("Prix achat : ");

        jLabel13.setText("Garantie : ");

        jLabel14.setText("mois");

        jButton4.setText("Retour");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton3.setText("Enregistrer les modifications");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton5.setText("Annuler");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(ED_Nom, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addGap(18, 18, 18)
                                .addComponent(ED_NumSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ED_NumCompta))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ComboType, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(79, 79, 79)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabel11)
                                                .addGap(18, 18, 18)
                                                .addComponent(ED_Date, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel12)
                                                    .addComponent(jLabel13))
                                                .addGap(24, 24, 24)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                    .addComponent(ED_Prix, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                        .addComponent(ED_Garantie)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(jLabel14))))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(137, 137, 137)
                                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addGap(10, 10, 10))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(ComboYear, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel5)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(ComboSecteur, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addGap(20, 20, 20))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(189, 189, 189))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton3)
                                        .addGap(0, 0, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(EDTypeLum, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(BtnAdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(ComboType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(ComboYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ComboSecteur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(ED_NumCompta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(ED_Date, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ED_NumSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)
                        .addComponent(ED_Prix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ED_Nom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel13)
                        .addComponent(ED_Garantie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel14, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(EDTypeLum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(53, 53, 53)
                        .addComponent(BtnAdd))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel10)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton4)
                            .addComponent(jButton5))
                        .addContainerGap(26, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton3))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void EDTypeLumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EDTypeLumActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_EDTypeLumActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        jButton3.setVisible(false);
        for (Map.Entry<Integer, Classes.Type> t : listeType.entrySet()) {
            ComboType.addItem(t.getValue());
        }

        for (Map.Entry<Integer, Secteur> s : listeSecteur.entrySet()) {
            ComboSecteur.addItem(s.getValue());
        }

        dtm = (DefaultTableModel) jTable1.getModel();
        remplirJTable();
    }//GEN-LAST:event_formWindowOpened

    private void ComboTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ComboTypeActionPerformed
    }//GEN-LAST:event_ComboTypeActionPerformed

    private void BtnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAddActionPerformed



        if (BtnAdd.getText() == "Ajouter") {

            try {
                Retroprojecteur myRetroprojecteur = new Retroprojecteur();
                RetroprojecteurDAO myRetroprojecteurDAO = new RetroprojecteurDAO(DBConnect.getInstance());

                myRetroprojecteur.setDescriptif(ED_descriptif.getText());
                myRetroprojecteur.setNumCompta(Integer.decode(ED_NumCompta.getText()));
                myRetroprojecteur.setNumSerie(ED_NumSerie.getText());
                myRetroprojecteur.setNom(ED_Nom.getText());
                myRetroprojecteur.setDateHT(ED_Date.getText());
                myRetroprojecteur.setPrixHT(Double.parseDouble(ED_Prix.getText()));
                myRetroprojecteur.setGarantie(Integer.decode(ED_Garantie.getText()));
                myRetroprojecteur.setTypeAmp(EDTypeLum.getText());
                myRetroprojecteur.setIdT(((Classes.Type) ComboType.getSelectedItem()).getIdT());
                myRetroprojecteur.setIdSc(((Secteur) ComboSecteur.getSelectedItem()).getIdSc());

                myRetroprojecteurDAO.insert(myRetroprojecteur);
                long CB = 0000000000000;
                listeRetroprojecteur.put(CB, myRetroprojecteur);
                dtm = (DefaultTableModel) jTable1.getModel();
                remplirJTable();

                JOptionPane.showMessageDialog(this, "Votre rétroprojecteur " + ED_Nom.getText() + " a été ajouté avec succès !", "Information", JOptionPane.INFORMATION_MESSAGE);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Une erreur est survenue durant l'enregistrement du matériel => " + e.toString(), "HOUSTON we've had problem !!!", JOptionPane.ERROR_MESSAGE);
            }
    }//GEN-LAST:event_BtnAddActionPerformed
    else {
            retroprojecteurGlobal = (Retroprojecteur) jTable1.getValueAt(jTable1.getSelectedRow(), 0);
            RetroprojecteurDAO myRetroprojecteurDAO = new RetroprojecteurDAO(DBConnect.getInstance());
            try {
                retroprojecteurGlobal.setDescriptif(ED_descriptif.getText());
                retroprojecteurGlobal.setNumCompta(Integer.decode(ED_NumCompta.getText()));
                retroprojecteurGlobal.setNumSerie(ED_NumSerie.getText());
                retroprojecteurGlobal.setNom(ED_Nom.getText());
                retroprojecteurGlobal.setDateHT(ED_Date.getText());
                retroprojecteurGlobal.setPrixHT(Double.parseDouble(ED_Prix.getText()));
                retroprojecteurGlobal.setGarantie(Integer.decode(ED_Garantie.getText()));
                retroprojecteurGlobal.setTypeAmp(ED_Garantie.getText());
                retroprojecteurGlobal.setIdT(((Classes.Type) ComboType.getSelectedItem()).getIdT());
                retroprojecteurGlobal.setIdSc(((Secteur) ComboSecteur.getSelectedItem()).getIdSc());

                myRetroprojecteurDAO.update(retroprojecteurGlobal);
                dtm = (DefaultTableModel) jTable1.getModel();
                remplirJTable();

                JOptionPane.showMessageDialog(this, "Votre rétroprojecteur " + ED_Nom.getText() + " a été modifié avec succès !", "Information", JOptionPane.INFORMATION_MESSAGE);


            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Une erreur est survenue durant l'enregistrement du matériel => " + e.toString(), "HOUSTON we've had problem !!!", JOptionPane.ERROR_MESSAGE);
            }

        }
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        this.mainFrame.setVisible(true);
    }//GEN-LAST:event_formWindowClosed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        RetroprojecteurDAO myRetroprojecteurDAO = new RetroprojecteurDAO(DBConnect.getInstance());

        try {
            retroprojecteurGlobal.setDescriptif(ED_descriptif.getText());
            retroprojecteurGlobal.setNumCompta(Integer.decode(ED_NumCompta.getText()));
            retroprojecteurGlobal.setNumSerie(ED_NumSerie.getText());
            retroprojecteurGlobal.setNom(ED_Nom.getText());
            retroprojecteurGlobal.setDateHT(ED_Date.getText());
            retroprojecteurGlobal.setPrixHT(Double.parseDouble(ED_Prix.getText()));
            retroprojecteurGlobal.setGarantie(Integer.decode(ED_Garantie.getText()));
            retroprojecteurGlobal.setTypeAmp(EDTypeLum.getText());
            retroprojecteurGlobal.setIdT(((Classes.Type) ComboType.getSelectedItem()).getIdT());
            retroprojecteurGlobal.setIdSc(((Secteur) ComboSecteur.getSelectedItem()).getIdSc());

            myRetroprojecteurDAO.update(retroprojecteurGlobal);

            dtm = (DefaultTableModel) jTable1.getModel();
            remplirJTable();

            JOptionPane.showMessageDialog(this, "Votre rétroprojecteur " + ED_Nom.getText() + " a été modifié avec succès !", "Information", JOptionPane.INFORMATION_MESSAGE);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Une erreur est survenue durant l'enregistrement du rétroprojecteur => " + e.toString(), "Une erreur est survenue !", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        try {

            retroprojecteurGlobal = (Retroprojecteur) jTable1.getValueAt(jTable1.getSelectedRow(), 0);

            ED_NumCompta.setText(Integer.toString(retroprojecteurGlobal.getNumCompta()));
            ED_Date.setText(retroprojecteurGlobal.getDateHT());
            ED_NumSerie.setText(retroprojecteurGlobal.getNumSerie());
            ED_Prix.setText(Double.toString(retroprojecteurGlobal.getPrixHT()));
            ED_Nom.setText(retroprojecteurGlobal.getNom());
            ED_Garantie.setText(Integer.toString(retroprojecteurGlobal.getGarantie()));
            ED_descriptif.setText(retroprojecteurGlobal.getDescriptif());
            EDTypeLum.setText(retroprojecteurGlobal.getTypeAmp());

            if (retroprojecteurGlobal.getNumCB() != 0) {
                BtnAdd.setText("Enregistrer");
            }

        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Veuillez choisir un rétroprojecteur dans la liste !", "Une erreur est survenue", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        if (jTable1.getSelectedRowCount()!=0) {
            RetroprojecteurDAO myRetroprojecteurDAO = new RetroprojecteurDAO(DBConnect.getInstance());

            try {
                int reply = JOptionPane.showConfirmDialog(null, "Voulez-vous supprimer ce rétroprojecteur ?", "Confirmation avant suppression", JOptionPane.YES_NO_OPTION);
                if (reply == JOptionPane.YES_OPTION) {
                    retroprojecteurGlobal = (Retroprojecteur) jTable1.getValueAt(jTable1.getSelectedRow(), 0);

                    myRetroprojecteurDAO.delete(retroprojecteurGlobal);

                    listeRetroprojecteur.remove(retroprojecteurGlobal.getNumCB());

                    dtm = (DefaultTableModel) jTable1.getModel();
                    remplirJTable();
                    JOptionPane.showMessageDialog(this, "Suppression terminée !", "Information", JOptionPane.INFORMATION_MESSAGE);
                }

            } catch (Exception e) {
            }
        }else{
            JOptionPane.showMessageDialog(this, "Veuillez séléctionner un rétroprojecteur dans la liste !", "Une erreur est survenue !!!", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        ED_descriptif.setText("");
        ED_NumCompta.setText("");
        ED_NumSerie.setText("");
        ED_Nom.setText("");
        ED_Date.setText("");
        ED_Prix.setText("");
        ED_Garantie.setText("");
        EDTypeLum.setText("");

        BtnAdd.setText("Ajouter");
    }//GEN-LAST:event_jButton5ActionPerformed

    private void remplirJTable() {
        while (dtm.getRowCount() != 0) {
            dtm.removeRow(0);
        }

        for (Map.Entry<Long, Retroprojecteur> r : listeRetroprojecteur.entrySet()) {
            Vector v = new Vector();
            v.add(r.getValue());
            v.add(r.getValue().getNom());
            v.add(r.getValue().getDescriptif());
            v.add(r.getValue().getTypeAmp());
            dtm.addRow(v);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(vueRetroprojecteur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(vueRetroprojecteur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(vueRetroprojecteur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(vueRetroprojecteur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAdd;
    private javax.swing.JComboBox ComboSecteur;
    private javax.swing.JComboBox ComboType;
    private javax.swing.JComboBox ComboYear;
    private javax.swing.JTextField EDTypeLum;
    private javax.swing.JTextField ED_Date;
    private javax.swing.JTextField ED_Garantie;
    private javax.swing.JTextField ED_Nom;
    private javax.swing.JTextField ED_NumCompta;
    private javax.swing.JTextField ED_NumSerie;
    private javax.swing.JTextField ED_Prix;
    private javax.swing.JTextArea ED_descriptif;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
